package com.hlhj.funlike_business.activity.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.CommentListBean;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class CommentAdp extends BaseQuickAdapter<CommentListBean.DataBeanX.DataBean,BaseViewHolder> {
    public CommentAdp(@Nullable List<CommentListBean.DataBeanX.DataBean> data) {
        super(R.layout.adp_comment,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final CommentListBean.DataBeanX.DataBean item) {
        final CircleImageView icon = helper.getView(R.id.img_icon);
        TextView customerName = helper.getView(R.id.tv_customername);
        RatingBar ratingBar = helper.getView(R.id.ratingbar);
        TextView tv_content = helper.getView(R.id.tv_content);
        TextView orderNum = helper.getView(R.id.tv_orderNum);
        RecyclerView recycle_list = helper.getView(R.id.recycle_list);
        TextView tv_del = helper.getView(R.id.tv_del);
        TextView tv_reply = helper.getView(R.id.tv_reply);
        LinearLayout ll_reply = helper.getView(R.id.ll_reply);
        TextView tv_replycontent = helper.getView(R.id.tv_replycontent);
        final EditText edit_content = helper.getView(R.id.edit_content);

        Glide.with(mContext).load(item.getAvatar()).into(icon);
        customerName.setText(item.getUser_name());
        orderNum.setText(item.getOrder_sn());
        tv_content.setText(item.getContent());
        ratingBar.setNumStars(5);
        ratingBar.setRating((float)item.getStars());

        List<String> stringList = new ArrayList<>();
        for (String img:item.getImgs()){
            stringList.add(img);
        }
        CommentImgAdp commentImgAdp = new CommentImgAdp(stringList);
        recycle_list.setLayoutManager(new GridLayoutManager(mContext,3));
        recycle_list.setAdapter(commentImgAdp );

        if (!"".equals(item.getReply_content())&&null!=item.getReply_content()){
            ll_reply.setVisibility(View.VISIBLE);
            tv_reply.setVisibility(View.INVISIBLE);
            tv_replycontent.setText(item.getReply_content());
        }else {
            tv_reply.setVisibility(View.VISIBLE);
            ll_reply.setVisibility(View.GONE);
        }

        tv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.loadDel(item.getId());
                }
            }
        });

        edit_content.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String toString = s.toString();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        tv_reply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener!=null){
                    listener.loadReply(item.getId());
                }
            }
        });
    }



    public interface getResult{
        void loadDel(int id);

        void loadReply(int id);
    }

    public getResult listener;

    public void setListener(getResult listener) {
        this.listener = listener;
    }

//    public interface getReplyResult{
//
//    }
//
//    public getReplyResult click;
//
//    public void setClick(getReplyResult click) {
//        this.click = click;
//    }
}
